# -*- coding: utf-8 -*-

"""
api 测试包
"""

__author__ = 'Lei Chen'

__all__ = ['config', 'ApiManager']

from api import config, objects, exceptions


class ApiManager(object):
    def __init__(self, parser):
        self._cache = {}
        self.parser = parser

    def create(self, system):
        if system == 'WEB':
            return objects.Web(self.parser)
        elif system == 'API':
            return objects.Api(self.parser)
        elif system == 'ADMIN':
            return objects.Admin(self.parser)
        elif system == 'WALLET':
            return objects.Wallet(self.parser)
        elif system == 'PARTNER':
            return objects.Partner(self.parser)
        elif system == 'TRADING':
            return objects.Trading(self.parser)
        elif system == 'APP':
            return objects.App(self.parser)
        else:
            raise exceptions.CreateApiError('%s is 不存在' % system)

    def get(self, system):
        api = self._cache.get(system)
        if not api:
            api = self.create(system)
            self._cache[system] = api
        return api
